<template>
  <div class="login-page">
    <div class="login-content">
      <div class="login-card">
        <div class="login-header">
          <h1>XXXXX系统</h1>
        </div>

        <a-form
          ref="formRef"
          :model="formState"
          :rules="loginRules"
          class="login-form"
          layout="vertical"
        >
          <a-form-item name="username">
            <a-input
              v-model:value="formState.username"
              placeholder="请输入用户名"
              size="large"
              allow-clear
            >
              <template #prefix>
                <UserOutlined />
              </template>
            </a-input>
          </a-form-item>

          <a-form-item name="password">
            <a-input-password
              v-model:value="formState.password"
              placeholder="请输入密码"
              size="large"
              allow-clear
              @pressEnter="handleLogin"
            >
              <template #prefix>
                <LockOutlined />
              </template>
            </a-input-password>
          </a-form-item>

          <a-form-item class="py-4">
            <a-button type="primary" size="large" block @click="handleLogin">
              立即登录
            </a-button>
          </a-form-item>
        </a-form>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// 组件命名
defineOptions({
  name: 'Login',
});

// 导入Vue组合式API
import { reactive, ref, onMounted, onBeforeUnmount } from 'vue';
import { useRouter } from 'vue-router';
import {
  UserOutlined,
  LockOutlined,
  DesktopOutlined,
  PartitionOutlined,
  StarOutlined,
  BookOutlined as IconBook,
} from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';
import { login } from '@/api/manage.api';

const router = useRouter();
const formRef = ref();

const formState = reactive({
  username: 'admin',
  password: '123456',
});

const loginRules = {
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
    {
      min: 2,
      max: 20,
      message: '用户名长度在 2 到 20 个字符',
      trigger: 'blur',
    },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 6, max: 20, message: '密码长度在 6 到 20 个字符', trigger: 'blur' },
  ],
};

const handleLogin = () => {
  formRef.value.validate().then(() => {
    login({
      user_name: 'admin',
      password: '123456',
    }).then(result => {
      router.push('/home');
    });
  });
};

// 生命周期钩子
onMounted(() => {
  console.log('组件已挂载');
});

onBeforeUnmount(() => {
  console.log('组件即将卸载');
});
</script>

<style scoped lang="scss">
.login-page {
  height: 100vh;
  width: 100vw;
  // background: linear-gradient(
  //   135deg,
  //   rgba(255, 126, 51, 0.9),
  //   rgba(255, 215, 0, 0.8),
  //   rgba(74, 144, 226, 0.9)
  // );
  // background-size: 400% 400%;
  // animation: gradientShift 8s ease infinite;
  background: url('/public/bg1.jpg') center center/cover no-repeat;
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.login-content {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 20px;
}

.login-card {
    // background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 32px 64px rgba(0, 0, 0, 0.1),
      0 16px 32px rgba(255, 126, 51, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: cardFadeIn 0.8s ease-out;
  }

  @keyframes cardFadeIn {
    from {
      opacity: 0;
      transform: translateY(30px) scale(0.9);
    }
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }

  /* 半透明底色+描边，形成“玻璃”质感 */
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);

  /* 核心：让“背后的内容”被模糊/增饱和 */
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%); /* 兼容 iOS Safari */

  color: #fff;
}

.login-header {
  text-align: center;
  margin-bottom: 40px;

  h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, #ff7e33, #4a90e2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
  }
}
</style>

